#!/usr/bin/env bash
#先把u盘插到电视盒子上抓包日志，然后使用wireshark导出网址，再使用本脚本
set -e
if [[ $1 == "-h" || $1 == "--help" ]]; then
    echo "帮助:"
    echo "    iptv.sh 日志.txt iptv.m3u"
    echo "    若要去重，就加上第三个参数，任意值均可"
    exit 0
fi
echo "#EXTM3U" >> $2
sed -n '/Full.*http:\/\/hwrr.jx.chinamobile/p' $1 |sed -e 's/.*\(http.*\).zoneoffset.*/\1/' -e '/\.ts$/d' >> $2
if [[ $# == 3 ]]; then
    cp $2 /tmp/_tmpiptv20240602.txt
    awk '!x[$0]++' /tmp/_tmpiptv20240602.txt >$2
    rm /tmp/_tmpiptv20240602.txt
fi
